package com.lcxw.hxzbapi.controller.economycontroller;

import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lcxw.hxzbapi.entity.response.Response;

@RestController
@RequestMapping("/api/coin")
@CrossOrigin
@Validated
@Slf4j
public class CoinController {

    @Resource
    CoinRealization coinRealization;

    /**
     * 1、用户获取自己所拥有的虚拟货币数量的接口
     */
    @PostMapping("/myCoin/get")
    public Response getMyCoin(@RequestBody JSONObject requestParms)    {

        long userId = Long.parseLong(requestParms.getString("userId"));

        int earnBean,ratio;
        try {
            earnBean = coinRealization.getMemberCoin(userId);
            ratio = coinRealization.getRatio();
        } catch (Exception e) {
            return Response.dbFail(log,"get member");
        }

        JSONObject data = new JSONObject();
        data.put("earnBean",earnBean);
        data.put("ratio",ratio);

        return Response.ok(data);
    }


}
